<template>
  <div class="album">
    <div v-if="albumsList.length != 0">
      <div class="content">
        <div
          class="content_item"
          v-for="item in albumsList"
          :key="item.id"
          @click="toAlbumDetailsPage(item.id)"
        >
          <div class="content_item_img">
            <GlobalImageDeep
              :url="item.picUrl"
              :imgWidth="224"
              :imgHeight="224"
            />
            <!-- 播放按钮 -->
            <GlobalPlayMask :maskWidth="64" :maskHeight="64" />
          </div>
          <p class="one_txt_cut">{{ item.name }}</p>
          <i class="one_txt_cut"> {{ item.artist.name }}</i>
        </div>
      </div>
      <!-- 分页 -->
      <el-row type="flex" justify="center" style="padding-top: 20px">
        <el-pagination
          layout="total,prev, pager, next"
          :total="total"
          :page-size="queryInfo.limit"
          @current-change="paginationCurrentChange"
          :current-page="currentPage"
          popper-class="select"
        >
        </el-pagination>
      </el-row>
    </div>
    <el-row v-else type="flex" justify="center" style="padding-top: 20px">
      <img
        src="../../../assets/images/loading.3708220b.gif"
        alt=""
        height="200"
        width="200"
      />
    </el-row>
  </div>
</template>

<script>
import { getSearch } from "../../../api/searchApi";
export default {
  name: "album",
  components: {},
  props: {
    search: {
      required: true,
      type: String,
    },
  },
  data() {
    return {
      albumsList: [],
      queryInfo: {
        keywords: this.search,
        limit: 20,
        offset: 0,
        type: 10, // 10 代表的是 专辑
      },
      total: "",
      currentPage: 1,
    };
  },
  created() {
    this.getSearchMethod();
  },
  watch: {
    search(newValue) {
      if (newValue.length !== 0) {
        this.queryInfo = {
          keywords: this.search,
          limit: 20,
          offset: 0,
          type: 10,
        };
        this.total = 0;
        this.currentPage = 1;
        this.getSearchMethod();
      }
    },
  },
  methods: {
    async getSearchMethod() {
      let result = await getSearch(this.queryInfo);
      if (result.code === 200) {
        this.albumsList = result.result.albums;
        this.total = result.result.albumCount;
      }
    },
    paginationCurrentChange(newPage) {
      this.queryInfo.offset = (newPage - 1) * this.queryInfo.limit;
      this.currentPage = newPage;
      // this.albumsList = [];
      this.getSearchMethod();
      // console.log(document.querySelector(".album").offsetTop);
      this.$utils.scrollTop(document.querySelector(".album").offsetTop, 200);
    },
    toAlbumDetailsPage(id) {
      this.$router.push(`/albumDetails/${id}`);
    },
  },
  computed: {},
};
</script>

<style lang="less" scoped>
.album {
  .content {
    padding: 15px 0;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .content_item {
      height: 316px;
      width: 288px;
      font-size: 14px;

      &:hover {
        /deep/ .playMask .play {
          display: block;
          cursor: pointer;
        }
      }

      .content_item_img {
        position: relative;
        width: 224px;
        height: 224px;
        &::before {
          content: "";
          position: absolute;
          top: 0;
          left: 30px;
          width: 100%;
          height: 100%;
          background: url("../../../assets/images/album-cover.png") no-repeat
            center;
        }
      }
      p {
        width: 224px;
        color: #333333;
        margin-top: 10px;
        margin-bottom: 10px;
        &:hover {
          color: @globalColor;
          animation: bounce 1s;
          cursor: pointer;
        }
      }
      i {
        width: 224px;
        display: block;
        color: #999999;
        &:hover {
          color: @globalColor;
          // animation: bounce 1s;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
